home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / system / bsvc-1.000 / bsvc-1 / bsvc-1.0.4 / src / Framework / BreakpointList.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-26  |  3.5 KB  |  150 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. // $Id: BreakpointList.cxx,v 1.1 1994/02/18 19:49:17 bmott Exp $
  3. ///////////////////////////////////////////////////////////////////////////////
  4. // BreakpointList.cxx
  5. //
  6. //   This class manages a list of breakpoints
  7. //
  8. //
  9. // BSVC "A Microprocessor Simulation Framework"
  10. // Copyright (c) 1993
  11. // By: Bradford W. Mott
  12. // November 23,1993
  13. //
  14. ///////////////////////////////////////////////////////////////////////////////
  15. // $Log: BreakpointList.cxx,v $
  16. // Revision 1.1  1994/02/18  19:49:17  bmott
  17. // Initial revision
  18. //
  19. ///////////////////////////////////////////////////////////////////////////////
  20.  
  21. #include "BreakpointList.hxx"
  22.  
  23. ///////////////////////////////////////////////////////////////////////////////
  24. // The class constructor
  25. ///////////////////////////////////////////////////////////////////////////////
  26. BreakpointList::BreakpointList()
  27. {
  28.   head=tail=(void*)0;
  29. }
  30.  
  31. ///////////////////////////////////////////////////////////////////////////////
  32. // Add a breakpoint to the list
  33. ///////////////////////////////////////////////////////////////////////////////
  34. void BreakpointList::Add(unsigned long address)
  35. {
  36.   BreakpointNode *p;
  37.  
  38.   // If the address is already in the list then just return
  39.   for(p=head; p!=(void*)0; p=p->next)
  40.     if(p->address == address)
  41.       return;
  42.  
  43.   // Create the new node for the linked list
  44.   p = new BreakpointNode;
  45.   p->address=address;
  46.   p->next=(void*)0; 
  47.  
  48.   // Put the node at the end of the linked list
  49.   if(tail==(void*)0)
  50.   {
  51.     head=tail=p; 
  52.   }
  53.   else
  54.   {
  55.     tail->next=p;
  56.     tail=p; 
  57.   } 
  58.   return;
  59. }
  60.  
  61. ///////////////////////////////////////////////////////////////////////////////
  62. // Delete the breakpoint from the list
  63. ///////////////////////////////////////////////////////////////////////////////
  64. int BreakpointList::Delete(unsigned long address)
  65. {
  66.   BreakpointNode *p,*q;
  67.  
  68.   for(q=(void*)0,p=head; ((p->address!=address) &&
  69.       (p!=(void*)0)); q=p,p=p->next);
  70.  
  71.   if(p!=((void*)0))
  72.   {
  73.     // Unlink the BreakpointNode
  74.     if((p==head) && (p==tail))
  75.     {
  76.       head=tail=(void*)0;
  77.     }
  78.     else if (p==head)
  79.     {
  80.       head=p->next;
  81.     }
  82.     else if(p==tail)
  83.     {
  84.       q->next=(void*)0; 
  85.       tail=q;
  86.     }
  87.     else
  88.     {
  89.       q->next=p->next;
  90.     }
  91.  
  92.     // Free the breakpoint node
  93.     delete p;
  94.  
  95.     return(1);
  96.   }
  97.   else
  98.   {
  99.     return(0);
  100.   }
  101.  
  102. ///////////////////////////////////////////////////////////////////////////////
  103. // Return the number of breakpoints in the list
  104. ///////////////////////////////////////////////////////////////////////////////
  105. int BreakpointList::NumberOfBreakpoints()
  106. {
  107.   BreakpointNode *p;
  108.   int t=0;
  109.  
  110.   for(p=head;p!=(void*)0;p=p->next)
  111.     ++t;
  112.  
  113.   return(t);
  114. }
  115.  
  116. ///////////////////////////////////////////////////////////////////////////////
  117. // Get the break point with the given index (1=OK,0=ERROR)
  118. ///////////////////////////////////////////////////////////////////////////////
  119. int BreakpointList::GetBreakpoint(unsigned int index, unsigned long& address)
  120. {
  121.   BreakpointNode *p;
  122.   int t;
  123.  
  124.   for(t=0,p=head;(t<index) && (p!=(void*)0);++t,p=p->next);
  125.  
  126.   if(p!=(void*)0)
  127.   {
  128.     address=p->address;
  129.     return(1);
  130.   }
  131.  
  132.   return(0);
  133. }
  134.  
  135. ///////////////////////////////////////////////////////////////////////////////
  136. // Check to see if the given address is a breakpoint (1=YES,0=NO)
  137. ///////////////////////////////////////////////////////////////////////////////
  138. int BreakpointList::Check(unsigned long address)
  139. {
  140.   BreakpointNode *p;
  141.  
  142.   for(p=head;p!=(void*)0;p=p->next)
  143.     if(p->address == address)
  144.       return(1);
  145.  
  146.   return(0);
  147. }
  148.  
  149.